<template>
  <div id="app">
    <!-- <router-link to="/main">首页</router-link> 相当于a标签  -->
    <!-- <router-link to="/login">登录页</router-link> 相当于a标签  -->
    <router-view />
  </div>
</template>

<script>
export default {
  name: "App",
  mounted() {
    window.addEventListener("unload", this.saveState);
  },
  methods: {
    saveState() {
      if (this.$store.state.user.username) {
        localStorage.setItem(
          "userState",
          JSON.stringify(this.$store.state.user)
        );
      }
    },
  },
};
</script>
